﻿<UserControl xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"  x:Class="BizControl.Presentation.ActivityEditModule.Views.MarksView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:csla="clr-namespace:Csla.Xaml;assembly=Csla.Xaml"
             xmlns:controls="clr-namespace:BizControl.Presentation.Infrastructure.Controls;assembly=BizControl.Presentation.Infrastructure"
             xmlns:res="clr-namespace:BizControl.Presentation.Infrastructure.Properties;assembly=BizControl.Presentation.Infrastructure"
             xmlns:thisConverters="clr-namespace:BizControl.Presentation.ActivityEditModule.Converters"
             x:Name="MarksViewControl">

    <UserControl.Resources>
        <thisConverters:BoolToCompletedConverter x:Key="BoolToCompletedConverter" />
        <thisConverters:MarkIsActiveToBrushConverter x:Key="MarkIsActiveToBrushConverter" />
        <thisConverters:ConditionTypeToPathConverter x:Key="ConditionTypeToPathConverter" />
        <thisConverters:ConditionTypeToNameConverter x:Key="ConditionTypeToNameConverter" IsNameVeryShort="True" />
        <thisConverters:ConditionTypeToEnabledConverter x:Key="ConditionTypeToEnabledConverter" />
        <thisConverters:MarkStateToPathConverter x:Key="MarkStateToPathConverter" />
        <thisConverters:MarkStateToStringConverter x:Key="MarkStateToStringConverter" />

        <DataTemplate x:Key="MarksInfoBriefSetTemplate">
            <Grid x:Name="markGrid"
                  Background="{Binding Path=State, Converter={StaticResource MarkStateToBrushConverter}}">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="180" />
                    <ColumnDefinition Width="160" />
                    <ColumnDefinition Width="164" />
                    <ColumnDefinition Width="200" />
                    <ColumnDefinition Width="64" />
                    <ColumnDefinition Width="29" />
                    <ColumnDefinition Width="160" />
                </Grid.ColumnDefinitions>

                <StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Left">
                    <TextBox Text="{Binding Path=Name, UpdateSourceTrigger=PropertyChanged}"
                             TextWrapping="Wrap" AcceptsReturn="True" Width="150" Height="60" Margin="5"
                             Tag="{x:Static res:Captions.EmptyPrompt}"
                             HorizontalAlignment="Left" VerticalAlignment="Center"
                             ScrollViewer.CanContentScroll="True" VerticalScrollBarVisibility="Auto">
                        <TextBox.Background>
                            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                <GradientStop Color="#FFECEDB1" Offset="0"/>
                                <GradientStop Color="#FFE9ED22" Offset="0.5"/>
                                <GradientStop Color="#FFF8BF0A" Offset="1"/>
                            </LinearGradientBrush>
                        </TextBox.Background>
                    </TextBox>
                    <StackPanel>
                        <ContentControl Width="20" Height="20"
                                        Content="{Binding Path=State, Converter={StaticResource MarkStateToPathConverter}}"
                                        ToolTip="{Binding Path=State, Converter={StaticResource MarkStateToStringConverter}}" />
                        <csla:PropertyStatus Margin="2" Property="{Binding Path=Name}" />
                    </StackPanel>
                </StackPanel>
                <Border BorderThickness="0,0,1,0" HorizontalAlignment="Right" BorderBrush="{StaticResource SolidBorderBrush}" />

                <StackPanel Grid.Column="1" Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="2">
                    <ComboBox Width="150" Height="80"
                              VerticalAlignment="Center" HorizontalAlignment="Left"
                              ItemsSource="{Binding ElementName=MarksViewControl, Path=DataContext.Participants}"
                              SelectedValue="{Binding Path=ResponsibleParticipant, Mode=TwoWay}">
                        <ComboBox.ItemTemplate>
                            <DataTemplate>
                                <Border Margin="2" BorderThickness="0,0,0,1" BorderBrush="{StaticResource BorderLightBrush}">
                                    <StackPanel>
                                        <controls:CurrentUserControl DataContext="{Binding Path=Person}" FontSize="8" />
                                        <StackPanel Orientation="Horizontal" Margin="2">
                                            <TextBlock Text="Роль: " FontSize="10" VerticalAlignment="Top" />
                                            <TextBlock Text="{Binding Path=Role}" Width="100" TextWrapping="Wrap"
                                                       Foreground="Blue" FontSize="10" VerticalAlignment="Top" />
                                        </StackPanel>
                                    </StackPanel>
                                </Border>
                            </DataTemplate>
                        </ComboBox.ItemTemplate>
                    </ComboBox>
                </StackPanel>
                <Border Grid.Column="1" BorderThickness="0,0,1,0" BorderBrush="{StaticResource SolidBorderBrush}" />

                <Grid Grid.Column="2">
                    <Grid.RowDefinitions>
                        <RowDefinition />
                        <RowDefinition />
                    </Grid.RowDefinitions>
                    <StackPanel Orientation="Horizontal">
                        <DatePicker Width="140" Margin="2" FontSize="8pt" 
                                    VerticalAlignment="Center" HorizontalAlignment="Left" SelectedDateFormat="Long"
                                    SelectedDate="{Binding Path=DueDate, UpdateSourceTrigger=PropertyChanged}" />
                        <csla:PropertyStatus Margin="2" Property="{Binding Path=DueDate}"/>
                    </StackPanel>
                    <Border Grid.Row="2" 
                            Visibility="{Binding Path=IsActive, Converter={StaticResource BoolFalseToVisibilityConverter}}"
                            BorderThickness="0,1,0,0" VerticalAlignment="Bottom" BorderBrush="{StaticResource SolidBorderBrush}">
                        <Border.Triggers>
                            <EventTrigger RoutedEvent="Mouse.MouseEnter">
                                <EventTrigger.Actions>
                                    <BeginStoryboard>
                                        <Storyboard>
                                            <DoubleAnimation Duration="0:0:0.2" Storyboard.TargetName="border" Storyboard.TargetProperty="Opacity" To="1" />
                                        </Storyboard>
                                    </BeginStoryboard>
                                </EventTrigger.Actions>
                            </EventTrigger>
                            <EventTrigger RoutedEvent="Mouse.MouseLeave">
                                <EventTrigger.Actions>
                                    <BeginStoryboard>
                                        <Storyboard>
                                            <DoubleAnimation Duration="0:0:1" Storyboard.TargetName="border" Storyboard.TargetProperty="Opacity" To="0" />
                                        </Storyboard>
                                    </BeginStoryboard>
                                </EventTrigger.Actions>
                            </EventTrigger>
                        </Border.Triggers>
                        <Grid>
                            <Border x:Name="border" Background="{StaticResource BackgroundBrush3}" Opacity="0" />
                            <TextBlock HorizontalAlignment="Left" VerticalAlignment="Center" Margin="2">
                                <Hyperlink CommandParameter="{Binding}">
                                        <Hyperlink.Command>
                                            <MultiBinding Converter="{StaticResource TriggerConverter}">
                                                <Binding Path="DataContext.SetMarkCompleteCommand" ElementName="MarksViewControl" />
                                                <Binding />
                                            </MultiBinding>
                                        </Hyperlink.Command>
                                    <TextBlock Text="Завершить работу" />
                                </Hyperlink>
                            </TextBlock>
                        </Grid>
                    </Border>
                </Grid>
                <Border Grid.Column="2" BorderThickness="0,0,1,0" BorderBrush="{StaticResource SolidBorderBrush}" />

                <Grid Grid.Column="3">
                    <Grid.RowDefinitions>
                        <RowDefinition />
                        <RowDefinition />
                    </Grid.RowDefinitions>
                    <ScrollViewer Height="60" CanContentScroll="True" VerticalScrollBarVisibility="Auto">
                        <ItemsControl ItemsSource="{Binding Path=Conditions}" HorizontalAlignment="Left" VerticalAlignment="Top">
                            <ItemsControl.ItemsPanel>
                                <ItemsPanelTemplate>
                                    <WrapPanel />
                                </ItemsPanelTemplate>
                            </ItemsControl.ItemsPanel>
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <StackPanel Orientation="Horizontal">
                                        <ContentControl Margin="2" Width="15" Height="15" 
                                                        Content="{Binding Path=Type, Converter={StaticResource ConditionTypeToPathConverter}}" />
                                        <TextBlock Margin="2" TextWrapping="Wrap" Width="160"
                                                   IsEnabled="{Binding Path=Type, Converter={StaticResource ConditionTypeToEnabledConverter}}">
                                        <Hyperlink>
                                            <Run FontWeight="Bold">
                                                <Run.Text>
                                                    <MultiBinding Converter="{StaticResource ConditionTypeToNameConverter}">
                                                        <Binding Path="Type" Mode="OneWay" />
                                                        <Binding Path="RequiredMark" Mode="OneWay" />
                                                        <Binding Path="RequiredActivity" Mode="OneWay" />
                                                    </MultiBinding>
                                                </Run.Text>
                                            </Run>
                                        </Hyperlink>
                                        </TextBlock>
                                    </StackPanel>
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                        </ItemsControl>
                    </ScrollViewer>
                    <Border Grid.Row="1" BorderThickness="0,1,0,0" VerticalAlignment="Bottom" BorderBrush="{StaticResource SolidBorderBrush}">
                        <Border.Triggers>
                            <EventTrigger RoutedEvent="Mouse.MouseEnter">
                                <EventTrigger.Actions>
                                    <BeginStoryboard>
                                        <Storyboard>
                                            <DoubleAnimation Duration="0:0:0.2" Storyboard.TargetName="border1" Storyboard.TargetProperty="Opacity" To="1" />
                                        </Storyboard>
                                    </BeginStoryboard>
                                </EventTrigger.Actions>
                            </EventTrigger>
                            <EventTrigger RoutedEvent="Mouse.MouseLeave">
                                <EventTrigger.Actions>
                                    <BeginStoryboard>
                                        <Storyboard>
                                            <DoubleAnimation Duration="0:0:1" Storyboard.TargetName="border1" Storyboard.TargetProperty="Opacity" To="0" />
                                        </Storyboard>
                                    </BeginStoryboard>
                                </EventTrigger.Actions>
                            </EventTrigger>
                        </Border.Triggers>
                        <Grid>
                            <Border x:Name="border1" Background="{StaticResource BackgroundBrush3}" Opacity="0" />
                            <TextBlock HorizontalAlignment="Left" VerticalAlignment="Center" Margin="2">
                                <Hyperlink Click="ManageCoditions_Click" 
                                           CommandParameter="{Binding}">
                                        <Hyperlink.Command>
                                            <MultiBinding Converter="{StaticResource TriggerConverter}">
                                                <Binding Path="DataContext.EditConditionsCommand" ElementName="MarksViewControl" />
                                                <Binding />
                                            </MultiBinding>
                                        </Hyperlink.Command>
                                    <TextBlock Text="Редактировать зависимости..." />
                                </Hyperlink>
                            </TextBlock>
                        </Grid>
                    </Border>
                </Grid>
                <Border Grid.Column="3" BorderThickness="0,0,1,0" BorderBrush="{StaticResource SolidBorderBrush}" />

                <telerik:RadNumericUpDown Grid.Column="4" Width="60" VerticalAlignment="Center" Margin="2" FontSize="12" FontWeight="Bold"
                                          NumberDecimalDigits="0"
                                          VerticalContentAlignment="Center" HorizontalContentAlignment="Center"
                                          Maximum="100" Minimum="0" Value="{Binding Path=Weight}" />
                <Border Grid.Column="4" BorderThickness="0,0,1,0" BorderBrush="{StaticResource SolidBorderBrush}" />

                <Path Grid.Column="5" Height="15" HorizontalAlignment="Center" VerticalAlignment="Center" Width="25" Stretch="Uniform" Fill="LightGreen" 
                      Stroke="Black" StrokeThickness="1" Margin="2"
                      Data="F1 M 51.0467,23.5747C 51.0987,23.4961 51.1507,23.4188 51.1973,23.3361C 51.2466,23.248 51.2906,23.1573 51.3333,23.0668C 51.356,23.0175 51.3853,22.972 51.4333,22.8387C 51.4706,22.7413 51.5013,22.6427 51.5306,22.5441C 51.5546,22.4628 51.5787,22.3827 51.5974,22.3014C 51.62,22.2054 51.632,22.1053 51.648,22.0081C 51.6586,21.9241 51.672,21.8414 51.68,21.7574C 51.6866,21.6573 51.6853,21.5548 51.6853,21.4535C 51.6853,21.3734 51.6853,21.2921 51.68,21.212C 51.6733,21.1068 51.6573,21.004 51.6413,20.9C 51.6307,20.8228 51.62,20.7455 51.6013,20.6667C 51.58,20.5654 51.5493,20.4655 51.5186,20.3654C 51.4947,20.2867 51.4706,20.2108 51.408,20.0294C 51.3826,19.9667 51.3466,19.9108 51.3173,19.8507C 51.2813,19.7734 51.244,19.7001 51.2026,19.6254C 51.1533,19.536 51.096,19.4481 51.0386,19.3641C 50.992,19.296 50.948,19.2281 50.8973,19.1641C 50.8306,19.0787 50.7573,18.9974 50.5853,18.8041L 32.8907,1.10803C 31.412,-0.369263 29.02,-0.369263 27.5453,1.10803C 26.0706,2.58276 26.0706,4.97876 27.5453,6.45203L 38.792,17.696L 3.78268,17.696C 2.47598,17.696 1.32532,18.3561 0.646637,19.3627C 0.23999,19.9655 0,20.6935 0,21.4774C 0,22.5201 0.423981,23.4655 1.108,24.1494C 1.79199,24.8334 2.7373,25.2574 3.78268,25.2574L 3.78268,25.2561L 38.7893,25.2561L 27.544,36.4988C 26.0706,37.9747 26.068,40.368 27.544,41.8441C 28.2827,42.5841 29.2506,42.9535 30.2187,42.9535C 31.1853,42.9535 32.1533,42.5854 32.8907,41.848L 50.5867,24.1481L 50.6893,24.0294C 50.7599,23.952 50.8293,23.8748 50.8933,23.7921C 50.948,23.7214 50.9973,23.6494 51.0467,23.5747 Z " />
                <Border Grid.Column="5" BorderThickness="0,0,1,0" BorderBrush="{StaticResource SolidBorderBrush}" />

                <StackPanel Grid.Column="6" Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="2">
                    <ComboBox Width="150" Height="80"
                              VerticalAlignment="Center" HorizontalAlignment="Left"
                              ItemsSource="{Binding ElementName=MarksViewControl, Path=DataContext.Participants}"
                              SelectedValue="{Binding Path=NextParticipant, Mode=TwoWay}">
                        <ComboBox.ItemTemplate>
                            <DataTemplate>
                                <Border Margin="2" BorderThickness="0,0,0,1" BorderBrush="{StaticResource BorderLightBrush}">
                                    <StackPanel>
                                        <controls:CurrentUserControl DataContext="{Binding Path=Person}" FontSize="8" />
                                        <StackPanel Orientation="Horizontal" Margin="2">
                                            <TextBlock Text="Роль: " FontSize="10" VerticalAlignment="Top" />
                                            <TextBlock Text="{Binding Path=Role}" Width="100" TextWrapping="Wrap"
                                                       Foreground="Blue" FontSize="10" VerticalAlignment="Top" />
                                        </StackPanel>
                                    </StackPanel>
                                </Border>
                            </DataTemplate>
                        </ComboBox.ItemTemplate>
                    </ComboBox>
                </StackPanel>

                <Border Grid.ColumnSpan="7" VerticalAlignment="Bottom" BorderThickness="0,0,0,1" BorderBrush="{StaticResource BorderDarkBrush}" />
            </Grid>
        </DataTemplate>
    </UserControl.Resources>

    <Grid>
        <StackPanel>
            <ToolBar>
                <Button HorizontalAlignment="Left" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch"
                        Width="25" Height="25" ToolTip="Добавить работу"
                        Command="{Binding Path=AddMarkCommand}"
                        Template="{StaticResource AddButtonTemplate}">
                </Button>
            </ToolBar>
            <Grid x:Name="markGrid" Visibility="{Binding Path=Model.HasMarks, Converter={StaticResource BoolToVisibilityConverter}}">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="180" />
                    <ColumnDefinition Width="160" />
                    <ColumnDefinition Width="164" />
                    <ColumnDefinition Width="200" />
                    <ColumnDefinition Width="64" />
                    <ColumnDefinition Width="29" />
                    <ColumnDefinition Width="160" />
                </Grid.ColumnDefinitions>
                <Border BorderThickness="0,0,1,0" BorderBrush="{StaticResource SolidBorderBrush}">
                    <TextBlock Text="Описание работы" FontWeight="Bold" VerticalAlignment="Center" Margin="5" />
                </Border>

                <Border Grid.Column="1" BorderThickness="0,0,1,0" BorderBrush="{StaticResource SolidBorderBrush}">
                    <TextBlock Text="Ответственный" FontWeight="Bold" VerticalAlignment="Center" Margin="2" />
                </Border>

                <Border Grid.Column="2" BorderThickness="0,0,1,0" BorderBrush="{StaticResource SolidBorderBrush}">
                    <TextBlock Text="К сроку" FontWeight="Bold" VerticalAlignment="Center" Margin="2" TextWrapping="Wrap" />
                </Border>
                <Border Grid.Column="2" BorderThickness="0,0,1,0" BorderBrush="{StaticResource SolidBorderBrush}" />

                <Border Grid.Column="3" BorderThickness="0,0,1,0" BorderBrush="{StaticResource SolidBorderBrush}">
                    <TextBlock Text="Зависимости работы" FontWeight="Bold" VerticalAlignment="Center" Margin="2" TextWrapping="Wrap" />
                </Border>
                <Border Grid.Column="3" BorderThickness="0,0,1,0" BorderBrush="{StaticResource SolidBorderBrush}" />

                <Border Grid.Column="4" BorderThickness="0,0,1,0" BorderBrush="{StaticResource SolidBorderBrush}">
                    <TextBlock Text="Вес работы" FontWeight="Bold" VerticalAlignment="Center" Margin="2" TextWrapping="Wrap" />
                </Border>
                <Border Grid.Column="4" BorderThickness="0,0,1,0" BorderBrush="{StaticResource SolidBorderBrush}" />

                <Border Grid.Column="5" BorderThickness="0,0,1,0" BorderBrush="{StaticResource SolidBorderBrush}" />
                <TextBlock Grid.Column="6" Text="Следующий ответственный" FontWeight="Bold" VerticalAlignment="Center" Margin="2" TextWrapping="Wrap" />

                <Border Grid.ColumnSpan="7" VerticalAlignment="Bottom" BorderThickness="0,0,0,1" BorderBrush="{StaticResource SolidBorderBrush}" />
            </Grid>

            <ItemsControl Background="{x:Null}" ItemsSource="{Binding Path=Model.Marks, Mode=OneWay}"
                          VirtualizingStackPanel.IsVirtualizing="True"
                          ItemTemplate="{StaticResource MarksInfoBriefSetTemplate}">
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <VirtualizingStackPanel />
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>
                <ItemsControl.Template>
                    <ControlTemplate>
                        <Border BorderThickness="{TemplateBinding Border.BorderThickness}"
                                Padding="{TemplateBinding Control.Padding}"
                                BorderBrush="{TemplateBinding Border.BorderBrush}"
                                Background="{TemplateBinding Panel.Background}"
                                SnapsToDevicePixels="True">
                            <ScrollViewer Padding="{TemplateBinding Control.Padding}" Focusable="False" CanContentScroll="True"
                                          VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">
                                <ItemsPresenter SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" />
                            </ScrollViewer>
                        </Border>
                    </ControlTemplate>
                </ItemsControl.Template>
            </ItemsControl>
        </StackPanel>
    </Grid>
</UserControl>
